import { IsArray, IsNotEmpty, IsString, ValidateNested } from 'class-validator';
import { Type } from 'class-transformer';

class Spec {
  @IsNotEmpty({ message: '请输入规格名称' })
  @IsString({ message: '规格名称必须是字符串' })
  name: string;

  @IsNotEmpty({ message: '请输入规格值' })
  @IsString({ message: '规格值必须是字符串' })
  value: string;
}

class Sku {
  @IsNotEmpty({ message: '请输入ID' })
  @IsString({ message: 'ID必须是字符串' })
  id: string;

  @IsNotEmpty({ message: '请输入价格' })
  price: number;

  @IsNotEmpty({ message: '请输入库存' })
  stock: number;

  @IsNotEmpty({ message: '请输入规格' })
  @IsArray({ message: '规格必须是数组' })
  @ValidateNested({ each: true })
  @Type(() => Spec)
  specs: Spec[];
}


export class ProductSkuDto {
  @IsNotEmpty({message: '请输入产品ID'})
  productId: number;

  @IsNotEmpty({message: '请输入产品规格'})
  @IsArray({ message: '产品规格必须是数组' })
  @ValidateNested({ each: true })
  @Type(() => Sku)
  skuList: any[];
}